﻿--#include "data\config\recharge\HeroGodWeaponRechargeConfig.lua" once

function SendHeroGodWeaponRechargeState(sysarg)
	local sVar = Actor.getStaticVar(sysarg)
	local netPack = DataPack.allocPacket(sysarg, LogicCmd.miscSys.sysId, LogicCmd.miscSys.sub.sSendHeroGodWeaponData) 
	if not netPack then return end
	DataPack.writeInt(netPack, sVar.heroGodWeaponRechargeYuanBao or 0)
	DataPack.writeByte(netPack, sVar.heroGodWeaponRechargeState or 0)
	DataPack.flush(netPack)
end

function OnHeroGodWeaponRechargeWithDrawYuanBao(sysarg, nYuanBao)
	local sVar = Actor.getStaticVar(sysarg)
	sVar.heroGodWeaponRechargeYuanBao = (sVar.heroGodWeaponRechargeYuanBao or 0) + nYuanBao
	SendHeroGodWeaponRechargeState(sysarg)
end

function GetHeroGodWeaponRechargeAward(sysarg)
	local sVar = Actor.getStaticVar(sysarg)
	if not sVar.heroGodWeaponRechargeState and (sVar.heroGodWeaponRechargeYuanBao or 0) >= HeroGodWeaponRechargeConfig.yb then
		if CheckBagGridForAwardsEx(sysarg, HeroGodWeaponRechargeConfig.awards) == 0 then
			sVar.heroGodWeaponRechargeState = 1
			GiveCommonAwardEx(sysarg, HeroGodWeaponRechargeConfig.awards, LogIds.GodWeaponRechargeLogId, Lang.LogTips.GodWeaponRecharge)
			SendHeroGodWeaponRechargeState(sysarg)
			local msg = string.format(Lang.ScriptTips.HeroGodWeaponRecharge001, Actor.getName(sysarg))
			System.broadcastTipmsgLimitLev(msg, ttScreenCenter + ttChatWindow)
		else
			Actor.sendTipmsg(sysarg, Lang.ScriptTips.COM0015, ttFlyTip)
		end
	end
end

function HeroGodWeaponRechargeOp(sysarg, msgid, packet)
	local nType = DataPack.readByte(packet)
	if nType == 0 then
		SendHeroGodWeaponRechargeState(sysarg)
	elseif nType == 1 then
		GetHeroGodWeaponRechargeAward(sysarg)
	end
end